from plotly.graph_objs import Bar, Layout
from plotly import offline

from die import Die

die_1 = Die()
die_2 = Die()

results = []
for roll_num in range(1000):
    result = die_1.roll() + die_2.roll()
    results.append(result)

frequences = []
max = die_1.num_sides + die_2.num_sides
for val in range(2, max + 1):
    frequences.append(results.count(val))

x_val = list(range(2, max + 1))
data = [Bar(x=x_val, y=frequences)]

# Plotly默认只显示部分刻度值，'dtick': 1可以让其显示每个刻度值。
x_axis_config = {'title': '结果', 'dtick': 1}
# x_axis_config = {'title': '结果'}
y_axis_config = {'title': '频率'}
my_layout = Layout(title='掷两个D6骰子 1000次的结果',
                   xaxis=x_axis_config,
                   yaxis=y_axis_config)

offline.plot({'data': data, 'layout': my_layout}, filename='output/d6_d6.html')
